package com.zjdiepu.www.commpent;

import java.math.BigDecimal;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.enums.status.DpStatus;
import com.zjdiepu.www.base.enums.status.RemitStatus;
import com.zjdiepu.www.base.enums.type.AttachmentLabel;
import com.zjdiepu.www.base.enums.type.AttachmentSort;
import com.zjdiepu.www.base.enums.type.AttachmentType;
import com.zjdiepu.www.base.enums.type.ModeIDType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.commpent.mapper.yw.AbstractYwBusinessLoanVoNewMapper;
import com.zjdiepu.www.commpent.mapper.yw.YwBusinessBuyerVoMapper;
import com.zjdiepu.www.commpent.mapper.yw.YwBusinessCarVoMapper;
import com.zjdiepu.www.commpent.mapper.yw.YwBusinessDetailMapper;
import com.zjdiepu.www.commpent.mapper.yw.YwBusinessVoMapper;
import com.zjdiepu.www.commpent.mapper.yw.YwFeesVoMapper;
import com.zjdiepu.www.ibiz.base.ISysUserService;
import com.zjdiepu.www.ibiz.cw.ICwRemitCarService;
import com.zjdiepu.www.ibiz.dh.IDhLoanAfterService;
import com.zjdiepu.www.ibiz.dz.IDzRegistrationService;
import com.zjdiepu.www.ibiz.system.IBaseBusiUnitService;
import com.zjdiepu.www.ibiz.system.IBaseRemitAccountService;
import com.zjdiepu.www.ibiz.third.IJuheBrandService;
import com.zjdiepu.www.ibiz.third.IJuheCarService;
import com.zjdiepu.www.ibiz.third.IJuheCityService;
import com.zjdiepu.www.ibiz.third.IJuheProvinceService;
import com.zjdiepu.www.ibiz.third.IJuheSeriesService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessBuyerService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessCarService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessLoanEditService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessLoanService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessService;
import com.zjdiepu.www.ibiz.yw.IYwFeesService;
import com.zjdiepu.www.ibiz.yw.IYwFundApplyService;
import com.zjdiepu.www.model.base.dto.SysUser;
import com.zjdiepu.www.model.base.ext.SysUserExt;
import com.zjdiepu.www.model.cw.dto.CwRemitCar;
import com.zjdiepu.www.model.dh.dto.DhLoanAfter;
import com.zjdiepu.www.model.dh.ext.DhLoanAfterExt;
import com.zjdiepu.www.model.dz.dto.DzRegistration;
import com.zjdiepu.www.model.dz.ext.DzRegistrationExt;
import com.zjdiepu.www.model.system.dto.BaseBusiUnit;
import com.zjdiepu.www.model.system.dto.BaseRemitAccount;
import com.zjdiepu.www.model.third.dto.JuheBrand;
import com.zjdiepu.www.model.third.dto.JuheCar;
import com.zjdiepu.www.model.third.dto.JuheCity;
import com.zjdiepu.www.model.third.dto.JuheProvince;
import com.zjdiepu.www.model.third.dto.JuheSeries;
import com.zjdiepu.www.model.third.ext.JuheBrandExt;
import com.zjdiepu.www.model.third.ext.JuheCarExt;
import com.zjdiepu.www.model.third.ext.JuheCityExt;
import com.zjdiepu.www.model.third.ext.JuheProvinceExt;
import com.zjdiepu.www.model.third.ext.JuheSeriesExt;
import com.zjdiepu.www.model.yw.dto.YwBusinessBuyer;
import com.zjdiepu.www.model.yw.dto.YwBusinessCar;
import com.zjdiepu.www.model.yw.dto.YwBusinessLoan;
import com.zjdiepu.www.model.yw.dto.YwBusinessLoanEdit;
import com.zjdiepu.www.model.yw.dto.YwFees;
import com.zjdiepu.www.model.yw.dto.YwFundApply;
import com.zjdiepu.www.model.yw.ext.YwBusinessCarExt;
import com.zjdiepu.www.model.yw.ext.YwBusinessLoanEditExt;
import com.zjdiepu.www.model.yw.ext.YwBusinessLoanExt;
import com.zjdiepu.www.model.yw.ext.YwFeesExt;
import com.zjdiepu.www.model.yw.ext.YwFundApplyExt;
import com.zjdiepu.www.model.yw.response.YwBusinessDetail;
import com.zjdiepu.www.util.CachedEnums;
import com.zjdiepu.www.util.ExceptionHelper;
/**
 * 项目名称：dpqc-parent-manager-information <br/> 
 * 类名称：ViewScopeControllerHelper <br/>  
 * 类描述： 作用域数据赋值帮助类<br/>    
 * 创建人：xiongxiaotun <br/> 
 * 创建时间：2017年5月12日 上午9:01:41  <br/>   
 * 修改人：xiongxiaotun <br/> 
 * 修改时间：2017年5月12日 上午9:01:41   <br/>  
 * 修改备注：    <br/> 
 * @version V1.0   <br/>
 */
@Service
public class ViewScopeControllerHelper extends BaseController{
	/**
	 * 收支明细项目
	 * @param items
	 * @param key
	 * @return
	 */
	public static double getItem(List<Map<String, Double>> items, String key){
	    	if(StringUtils.isBlank(key) || CollectionUtils.isEmpty(items)) {
	    		return 0;
	    	}
	    	
	    	for(Map<String, Double> item : items) {
	    		String realKey = "";
	    		Object dataKey = item.get("KEY");
	    		if(dataKey == null) {
	    			continue;
	    		}
	    		if(dataKey instanceof String) {
	    			realKey = (String)dataKey;
	    		} else {
	    			realKey = new BigDecimal(dataKey.toString()).setScale(0).toString();
	    		}
	    		if(key.equals(realKey)) {
	    			return item.get("VALUE") == null ? 0 : item.get("VALUE");
	    		}
	    	}
	    	return 0;
	    }
	  
	/**
	 * 收支明细总计
	 * @param items
	 * @param key
	 * @return
	 */
    public static double countItems(List<Map<String, Double>> items, List<String> exludeKeys){
    	if(CollectionUtils.isEmpty(items)) {
    		return 0;
    	}
    	double sum = 0;
    	for(Map<String, Double> item : items) {
    		Object dataKey = item.get("KEY");
    		if(dataKey == null) {
    			continue;
    		}
    		String realKey = "";
    		if(dataKey instanceof String) {
    			realKey = (String)dataKey;
    		} else {
    			realKey = new BigDecimal(dataKey.toString()).setScale(0).toString();
    		}
    		if(exludeKeys == null || !exludeKeys.contains(realKey)) {
    			sum += item.get("VALUE") == null ? 0 : item.get("VALUE");
    		}
    	}
    	return sum;
    }
	@Resource
    private IJuheProvinceService juheProvinceService;
    @Resource
    private IJuheCityService juheCityService;
    @Resource
    private IYwBusinessCarService ywBusinessCarService;
    @Resource
    private IYwBusinessService ywBusinessService;
    @Resource
    private YwBusinessVoMapper ywBusinessVoMapper;
    @Resource
    private YwBusinessDetailMapper ywBusinessDetailMapper;
    @Resource
    private YwBusinessCarVoMapper ywBusinessCarVoMapper;
    @Resource
	protected IJuheBrandService juheBrandService;
	@Resource
	protected IJuheSeriesService juheSeriesService;
	@Resource
	protected IJuheCarService juheCarService;
	@Resource
    private IDhLoanAfterService dhLoanAfterService;
    @Resource
    private IYwBusinessLoanService ywBusinessLoanService;
    @Resource
    private IYwFeesService ywFeesService;
    @Resource
    private IDzRegistrationService dzRegistrationService;
    @Resource
    private IBaseRemitAccountService baseRemitAccountService;
    @Resource
    private IBaseBusiUnitService baseBusiUnitService;
    @Resource
    private IYwBusinessBuyerService ywBusinessBuyerService;
    @Resource
    private ISysUserService sysUserService;
    @Resource
    private AbstractYwBusinessLoanVoNewMapper ywBusinessLoanVoMapper;
    @Resource
	private IYwFundApplyService ywFundApplyService;
    @Resource
    private ICwRemitCarService cwRemitCarService;
    @Resource
    private YwFeesVoMapper ywFeesVoMpper;
    @Resource
    private YwBusinessBuyerVoMapper ywBusinessBuyerVoMapper;
    @Resource
    private IYwBusinessLoanEditService ywBusinessLoanEditService;
    
    /**
	 * @author xiongxiaotun <br/>
	 * @Title: preparedRegistrationPlates  <br/>
	 * @Description: 车牌登记 <br/>
	 * @param busiId
	 * @param customerId
	 * @param model
	 * @return DzRegistration
	 * @version V1.0  <br/>
	 */
	public DzRegistration preparedRegistrationPlates(String busiId, Model model){
		DzRegistrationExt dzRegistrationExt = new DzRegistrationExt();
		dzRegistrationExt.setRows(1);
		dzRegistrationExt.setBaseWhere();
		dzRegistrationExt.setBusiId(busiId);
		//业务详情
		DzRegistration dzRegistration = null;
		List<DzRegistration> dzRegistrations = dzRegistrationService.selectByExt(dzRegistrationExt);
		if(CollectionUtils.isNotEmpty(dzRegistrations)){
			dzRegistration = dzRegistrations.get(0);
			model.addAttribute("dzRegistration", dzRegistration);
		}
		return dzRegistration;
	}
    
    /**
     * @author xiongxiaotun <br/>
     * @Title: preparedHistoryBusiness  <br/>
     * @Description: 历史交易记录 <br/>
     * @param customerNo
     * @param model
     * @version V1.0  <br/>
     */
    public void preparedHistoryBusiness(String customerNo, Model model){
    	String history = ywBusinessService.queryHistoryByCustomerNo(customerNo);
    	model.addAttribute("historyBusiness", StringUtils.isBlank(history)?"-":(history.startsWith(",")?history.substring(1):history));
    }
    
    /**
     * @author xiongxiaotun <br/>
     * @Title: preparedNowTime  <br/>
     * @Description: 当前时间 <br/>
     * @param model
     * @version V1.0  <br/>
     */
    public void preparedNowTime(Model model){
    	model.addAttribute("now", new Date());
    }
    
    /**
     * @author xiongxiaotun <br/>
     * @Title: preparedAllocation  <br/>
     * @Description: 分配任务：同部门员工 <br/>
     * @param orgId
     * @param model
     * @version V1.0  <br/>
     */
    public List<SysUser> preparedAllocation(String orgId, Model model){
    	SysUserExt sysUserExt = new SysUserExt();
    	sysUserExt.setBaseWhere();
    	sysUserExt.withOutPage();
    	sysUserExt.setOrgId(orgId);
    	sysUserExt.setOrderSql("`UNAME` DESC");
    	List<SysUser> sysUsers = sysUserService.selectByExt(sysUserExt);
    	LinkedHashMap<String, String> idNames = sysUsers.stream().collect(Collectors.toMap(item -> item.getId(), item -> item.getUname(), 
    			(k,v) -> { throw new IllegalStateException(String.format("key重复 %s", k)); }, LinkedHashMap<String, String>::new));
    	model.addAttribute("users", idNames);
    	return sysUsers;
    }
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: preparedBusiness  <br/>
	 * @Description: 业务详情 <br/>
	 * @param busiId
	 * @param model
	 * @return YwBusinessDetail
	 * @version V1.0  <br/>
	 */
	public YwBusinessDetail preparedBusiness(String busiId, Model model){
		//业务详情
		YwBusinessDetail ywBusinessDetail = ywBusinessService.getMultiById(busiId);
		if (null == ywBusinessDetail) {
			ExceptionHelper.thow(ResultFlagType.MISSING);
		}
		ywBusinessDetailMapper.mapper(ywBusinessDetail);
		String orgCode = ywBusinessDetail.getOrgCode();
		if(StringUtils.isNotBlank(orgCode)) {
			if(orgCode.length() > 4) {
				orgCode = orgCode.substring(0,4);
				BaseBusiUnit baseBusiUnit_ = new BaseBusiUnit();
				baseBusiUnit_.setOrgCode(orgCode);
				baseBusiUnit_.notDeleted();
				BaseBusiUnit baseBusiUnit = baseBusiUnitService.selectRefined(baseBusiUnit_);
				ywBusinessDetail.setProviceOrgName(baseBusiUnit.getOrgName());
			} else {
				ywBusinessDetail.setProviceOrgName(ywBusinessDetail.getOrgName());
			}
		}
		model.addAttribute("ywBusinessDetail", ywBusinessDetail);
		return ywBusinessDetail;
	}
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: preparedBuyer  <br/>
	 * @Description: 主借人 <br/>
	 * @param busiId
	 * @param model
	 * @return YwBusinessDetail
	 * @version V1.0  <br/>
	 */
	public YwBusinessBuyer preparedBuyer(String busiId, Model model){
		//业务详情
		YwBusinessBuyer ywBusinessBuyer_ = new YwBusinessBuyer();
		ywBusinessBuyer_.setBusiId(busiId);
		ywBusinessBuyer_.setCarManType("03");
		ywBusinessBuyer_.setDpStatus(DpStatus.NORMAL.getCode());
		YwBusinessBuyer ywBusinessBuyer = ywBusinessBuyerService.selectRefined(ywBusinessBuyer_);
		if (null == ywBusinessBuyer) {
			ExceptionHelper.thow(ResultFlagType.MISSING);
		}
		ywBusinessBuyerVoMapper.mapper(ywBusinessBuyer);
		model.addAttribute("ywBusinessBuyer", ywBusinessBuyer);
		return ywBusinessBuyer;
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: preparedCar  <br/>
	 * @Description: 车辆信息  <br/>
	 * @param busiId
	 * @param model
	 * @param customerId
	 * @return YwBusinessCar
	 * @version V1.0  <br/>
	 */
	public YwBusinessCar preparedCar(String busiId,String customerId, Model model) {
		// 查询车辆
		YwBusinessCarExt ywBusinessCarExt = new YwBusinessCarExt();
		ywBusinessCarExt.setBaseWhere();
		ywBusinessCarExt.setRows(1);// 只能返回一条数据
		ywBusinessCarExt.setBusiId(busiId);
		List<YwBusinessCar> ywBusinessCars = ywBusinessCarService.selectByExt(ywBusinessCarExt);
		if (CollectionUtils.isNotEmpty(ywBusinessCars)) {
			YwBusinessCar ywBusinessCar = ywBusinessCars.get(0);
			ywBusinessCarVoMapper.mapper(ywBusinessCar);
			model.addAttribute("ywBusinessCar", ywBusinessCar);
			return ywBusinessCar;
		}
		return null;
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: preparedLoan  <br/>
	 * @Description: 车贷信息 <br/>
	 * @param busiId
	 * @param carId
	 * @param model
	 * @param carType
	 * @return 
	 * @version V1.0  <br/>
	 */
	public YwBusinessLoan preparedLoan(String busiId, String carId, Model model, String carType){
		if(StringUtils.isBlank(carId)) {
			return null;
		}
		// 车贷信息 
		YwBusinessLoanExt ywBusinessLoanExt = new YwBusinessLoanExt();
		ywBusinessLoanExt.setBaseWhere();
		ywBusinessLoanExt.setRows(1);// 只能返回一条数据
		ywBusinessLoanExt.setBusiId(busiId);
		ywBusinessLoanExt.setCarId(carId);
		List<YwBusinessLoan> ywBusinessLoans = ywBusinessLoanService
				.selectByExt(ywBusinessLoanExt);
		if (CollectionUtils.isNotEmpty(ywBusinessLoans)) {
			YwBusinessLoan ywBusinessLoan = ywBusinessLoans.get(0);
			ywBusinessLoan.setCarType(carType);
			ywBusinessLoanVoMapper.mapper(ywBusinessLoan);
			model.addAttribute("ywBusinessLoan", ywBusinessLoan);
			return ywBusinessLoan;
		}
		return null;
	}
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: preparedLoan  <br/>
	 * @Description: 车贷信息 <br/>
	 * @param busiId
	 * @param carId
	 * @param model
	 * @param carType
	 * @return 
	 * @version V1.0  <br/>
	 */
	public YwBusinessLoanEdit preparedLoanEdit(String busiId, String carId, Model model, String carType){
		if(StringUtils.isBlank(carId)) {
			return null;
		}
		// 车贷信息 
		YwBusinessLoanEditExt ywBusinessLoanEditExt = new YwBusinessLoanEditExt();
		ywBusinessLoanEditExt.setBaseWhere();
		ywBusinessLoanEditExt.setRows(1);// 只能返回一条数据
		ywBusinessLoanEditExt.setBusiId(busiId);
		ywBusinessLoanEditExt.setCarId(carId);
		List<YwBusinessLoanEdit> ywBusinessLoansEdit = ywBusinessLoanEditService
				.selectByExt(ywBusinessLoanEditExt);
		if (CollectionUtils.isNotEmpty(ywBusinessLoansEdit)) {
			YwBusinessLoanEdit ywBusinessLoanEdit = ywBusinessLoansEdit.get(0);
			ywBusinessLoanEdit.setCarType(carType);
			ywBusinessLoanVoMapper.mapper(ywBusinessLoanEdit);
			model.addAttribute("ywBusinessLoanEdit", ywBusinessLoanEdit);
			return ywBusinessLoanEdit;
		}
		return null;
	}
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: preparedYwFee  <br/>
	 * @Description: 按揭日报表  <br/>
	 * @param busiId
	 * @param customerId
	 * @param model
	 * @return YwFees
	 * @version V1.0  <br/>
	 */
	public YwFees preparedYwFee(String busiId, String customerId, Model model){
		if(StringUtils.isBlank(customerId)) {
			return null;
		}
		YwFeesExt ywFeesExt = new YwFeesExt();
		ywFeesExt.setBaseWhere();
		ywFeesExt.setRows(1);
		ywFeesExt.setBusiId(busiId);
		List<YwFees> ywFees = ywFeesService.selectByExt(ywFeesExt);
		if(CollectionUtils.isNotEmpty(ywFees)) {
			YwFees ywFee = ywFees.get(0);
			ywFeesVoMpper.mapper(ywFee);
			model.addAttribute("ywFees", ywFee);
			return ywFee;
		}
		return null;
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: preparedRemitAccount  <br/>
	 * @Description: 打款名单 <br/>
	 * @param receiverId
	 * @param model
	 * @return
	 * @version V1.0  <br/>
	 */
	public BaseRemitAccount preparedRemitAccount(String receiverId, Model model){
		if(StringUtils.isBlank(receiverId)) {
			return null;
		}
		BaseRemitAccount remitAccount = baseRemitAccountService.selectById(receiverId);
		model.addAttribute("remitAccount", remitAccount);
		return remitAccount;
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: preparedFundApply  <br/>
	 * @Description: 申请垫资 <br/>
	 * @param busiId
	 * @param customerId
	 * @param addedStatus1 资金流转状态
	 * @param applyLoan 申请垫资页面
	 * @param model
	 * @return
	 * @version V1.0  <br/>
	 */
	public YwFundApply preparedFundApply(String busiId, String customerId, Integer addedStatus1, boolean applyLoan, Model model){
		if(StringUtils.isBlank(customerId)) {
			return null;
		}
		
		if(!applyLoan || (addedStatus1 != null && addedStatus1 == 100)) {
			YwFundApplyExt ywFundApplyExt = new YwFundApplyExt();
			ywFundApplyExt.setBaseWhere();
			ywFundApplyExt.setRows(1);
			ywFundApplyExt.setBusiId(busiId);
			ywFundApplyExt.setOrderSql("`CREATED` desc");
			List<YwFundApply> ywFundApplys = ywFundApplyService.selectByExt(ywFundApplyExt);
			if(CollectionUtils.isNotEmpty(ywFundApplys)) {
				YwFundApply ywFundApply = ywFundApplys.get(0);
				model.addAttribute("ywFundApply", ywFundApply);
				return ywFundApply;
			}
		}
		return null;
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: preparedRemitCar  <br/>
	 * @Description: 垫提车款 <br/>
	 * @param busiId
	 * @param customerId
	 * @param model
	 * @return CwRemitCar
	 * @version V1.0  <br/>
	 */
	public CwRemitCar preparedRemitCar(String busiId, String customerId, Model model){
		if(StringUtils.isBlank(customerId)) {
			return null;
		}
		CwRemitCar cwRemitCar = new CwRemitCar();
		cwRemitCar.setDpStatus(DpStatus.NORMAL.getCode());
		cwRemitCar.setBusiId(busiId);
		cwRemitCar.setStatusRemit(RemitStatus.WEI_TI_JIAO.getCode()); //优先选择未提交
		CwRemitCar cwRemitCarDb = cwRemitCarService.selectRefined(cwRemitCar);
		if(null == cwRemitCarDb) {
			cwRemitCar.setStatusRemit(RemitStatus.YI_TI_JIAO.getCode()); //选择最近的已提交数据
			cwRemitCar.setOrderSql("`MODIFIED` DESC");
			cwRemitCarDb = cwRemitCarService.selectRefined(cwRemitCar);
		}
		
		if(null != cwRemitCarDb) {
			model.addAttribute("cwRemitCar", cwRemitCarDb);
		}
		return cwRemitCarDb;
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: preparedLoanAfter  <br/>
	 * @Description: 贷后信息登记 <br/>
	 * @param busiId
	 * @param customerId
	 * @param model
	 * @return DhLoanAfter
	 * @version V1.0  <br/>
	 */
	public DhLoanAfter preparedLoanAfter(String busiId, String customerId, Model model){
		if(StringUtils.isBlank(customerId)) {
			return null;
		}
		// 查询贷后信息登记
		DhLoanAfterExt dhLoanAfterExt = new DhLoanAfterExt();
		dhLoanAfterExt.setBaseWhere();
		dhLoanAfterExt.setRows(1);// 只能返回一条数据
		dhLoanAfterExt.setBusiId(busiId);
		List<DhLoanAfter> dhLoanAfters = dhLoanAfterService.selectByExt(dhLoanAfterExt);
		if(CollectionUtils.isNotEmpty(dhLoanAfters)) {
			DhLoanAfter dhLoanAfter = dhLoanAfters.get(0);
			model.addAttribute("dhLoanAfter", dhLoanAfter);
			return dhLoanAfter;
		}
		return null;
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: preparedRegin  <br/>
	 * @Description: 地区信息 <br/>
	 * @param model
	 * @version V1.0  <br/>
	 */
	public void preparedRegin(Model model, String provinceId, String cityId){
		//省
    	Map<Object, Object> provinces_ = new LinkedHashMap<Object, Object>();
    	JuheProvinceExt juheProvinceExt = new JuheProvinceExt();
    	juheProvinceExt.withOutPage();
    	juheProvinceExt.setOrderSql("CONVERT(`REGION_CODE`, UNSIGNED) ASC");
    	juheProvinceExt.setBaseWhere();
		List<JuheProvince> provinces = juheProvinceService.selectByExt(juheProvinceExt);
		if(CollectionUtils.isNotEmpty(provinces)) {
			for(JuheProvince juheProvince : provinces) {
				provinces_.put(juheProvince.getProId(), juheProvince.getProName());
			}
		}
		model.addAttribute("provinces", provinces_);
		//市
		Map<Object, Object> cities_ = new LinkedHashMap<Object, Object>();
		if(CollectionUtils.isNotEmpty(provinces)) {
			JuheCityExt juheCityExt= new JuheCityExt();
			juheCityExt.setProId(StringUtils.isNotBlank(provinceId) ? provinceId : provinces.get(0).getProId());
			juheCityExt.withOutPage();
			juheCityExt.setBaseWhere();
			juheCityExt.setOrderSql("CONVERT(`REGION_CODE`, UNSIGNED) ASC");
			List<JuheCity> cities = juheCityService.selectByExt(juheCityExt);
			if(CollectionUtils.isNotEmpty(cities)) {
				for(JuheCity juheCity : cities) {
					cities_.put(juheCity.getCityId(), juheCity.getCityName());
				}
			}
		}
		model.addAttribute("cities", cities_);
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: preparedCarModel  <br/>
	 * @Description: 车品牌/车系/车型  <br/>
	 * @param model
	 * @version V1.0  <br/>
	 */
	public void preparedCarModel(Model model){
		//品牌
		Map<Object, Object> juheBrands_ = new LinkedHashMap<Object, Object>();
		JuheBrandExt juheBrandExt = new JuheBrandExt();
		juheBrandExt.withOutPage();
		juheBrandExt.setOrderSql("`BIG_PPNAME` ASC");
		juheBrandExt.setBaseWhere();
		List<JuheBrand> juheBrands = juheBrandService.selectByExt(juheBrandExt);
		if(CollectionUtils.isNotEmpty(juheBrands)) {
			for(JuheBrand juheBrand : juheBrands) {
				juheBrands_.put(juheBrand.getThirdId(), juheBrand.getBigPpname());
			}
		}
		
		model.addAttribute("juheBrands", juheBrands_);
		//车系
		Map<Object, Object> juheSeries_ = new LinkedHashMap<Object, Object>();
		List<JuheSeries> juheSeries = null;
		if(CollectionUtils.isNotEmpty(juheBrands)) {
			JuheSeriesExt juheSeriesExt = new JuheSeriesExt();
			juheSeriesExt.withOutPage();
			juheSeriesExt.setOrderSql("`XLNAME` ASC");
			juheSeriesExt.setBrandId(juheBrands.get(0).getThirdId());
			juheSeriesExt.setBaseWhere();
			juheSeries = juheSeriesService.selectByExt(juheSeriesExt);
			if(CollectionUtils.isNotEmpty(juheSeries)) {
				for(JuheSeries juheSery : juheSeries) {
					juheSeries_.put(juheSery.getXlid(), juheSery.getXlname());
				}
			}
		}
		model.addAttribute("juheSeries", juheSeries_);
		//车型
		Map<Object, Object> juheCars_ = new LinkedHashMap<Object, Object>();
		JuheCarExt juheCarExt = null;
		if(CollectionUtils.isNotEmpty(juheSeries)) {
			juheCarExt = new JuheCarExt();
			juheCarExt.withOutPage();
			juheCarExt.setOrderSql("`CXNAME` ASC");
			juheCarExt.setSeriesId(juheSeries.get(0).getXlid());
			juheCarExt.setBaseWhere();
			List<JuheCar> juheCars = juheCarService.selectByExt(juheCarExt);
			if(CollectionUtils.isNotEmpty(juheCars)) {
				for(JuheCar juheCar : juheCars) {
					juheCars_.put(juheCar.getCarId(), juheCar.getCxname());
				}
			}
		}
		model.addAttribute("juheCars", juheCars_);
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title: preparedAtta  <br/>
	 * @Description: 附件相关  <br/>
	 * @param model
	 * @version V1.0  <br/>
	 */
	public void preparedAttachmentEnum(Model model){
		//判断条件
		model.addAttribute("modeIDTypeNames", CachedEnums.getNames(ModeIDType.class));
		model.addAttribute("attachmentTypeNames", CachedEnums.getNames(AttachmentType.class));
		model.addAttribute("attachmentSortNames", CachedEnums.getNames(AttachmentSort.class));
		model.addAttribute("attachmentLabelNames", CachedEnums.getNames(AttachmentLabel.class));
		model.addAttribute("attachmentLabelNameValues", CachedEnums.getNameValues(AttachmentLabel.class));
	}
	
}
